package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult selectAll() {
        List list=nursingProjectService.seleteAll();
        return success(list);
    }

    @GetMapping
    @ApiOperation("分页查询护理项目")
    public ResponseResult selectByPage(
          @ApiParam("护理项目名称") String name,
          @ApiParam("护理项目状态")  Integer status,
          @ApiParam("当前页码")  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
          @ApiParam("每页显示数量")  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        PageResponse page = nursingProjectService.selectByPage(name,status,pageNum,pageSize);
        return success(page);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult selectById(
            @ApiParam("需查询护理项目id")@PathVariable Long id
    ) {
        NursingProjectVo vo = nursingProjectService.selectById(id);
        System.err.println(vo);
        return success(vo);
    }


    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult addNursingProject(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.addNursingProject(nursingProjectDto);
        return success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteNursingProject( @ApiParam("需删除护理项目id")@PathVariable Long id){
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改状态-禁用=0 启用=1 ")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "护理项目id",name = "id",required = true,dataType = "long"),
            @ApiImplicitParam(value = "护理项目启用禁用 禁用=0 启用=1 默认为1",name = "status",required = true,dataType = "int")
    })
    public ResponseResult updateStatus(
            @PathVariable Long id,
            @PathVariable Integer status){
        nursingProjectService.updateStatus(id,status);
        return success();
    }

    @PutMapping
    @ApiOperation("" +
            " ")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "修改护理项目dto",name = "dto",required = true,dataType = "NursingProjectDto")
    })
    public ResponseResult updateStatus(@RequestBody NursingProjectDto dto){
        nursingProjectService.update(dto);
        return success();
    }



}
